<template>
  <div>
    <!-- 顶部导航栏区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id == 0 ? 'mui-active' : '']"
            v-for="(item,index) in navList"
            :key="index"
            @tap="getCategoryImg(index)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图文列表区域 -->
    <ul class="photo-list">
      <router-link v-for="item in imgList" :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
        <img v-lazy="item.img_url" />
        <div class="contents">
          <h1 class="contents-title">{{item.title}}</h1>
          <div class="contents-zy">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import { tosat } from "mint-ui";
export default {
  data() {
    return {
      navList: [],
      imgList: []
    };
  },
  created() {
    this.getPhotoNav();
    this.getCategoryImg(0);
  },
  mounted() {
    // 当 组件中的DOM结构被渲染好并放到页面中后，会执行这个 钩子函数
    // 如果要操作元素了，最好在 mounted 里面，因为，这里时候的 DOM 元素 是最新的
    // 2. 初始化滑动控件
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    // 获取顶部导航栏
    getPhotoNav() {
      this.$http.get("api/getimgcategory").then(result => {
        result.data.message.unshift({ title: "全部", id: 0 });
        this.navList = result.data.message;
      });
    },
    // 获取图文列表
    getCategoryImg(cateId) {
      this.$http.get("api/getimages/" + cateId).then(result => {
        // console.log(result);
        if (result.data.status === 0) {
          this.imgList = result.data.message;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.photo-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  padding-bottom: 0;
  li {
    background-color: #fff;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 0 9px #999;
    position: relative;
  }
  img {
    width: 100%;
    vertical-align: middle;
  }
  img[lazy="loading"] {
    width: 40px;
    height: 300px;
    margin: auto;
  }
  .contents {
    color: white;
    text-align: left;
    position: absolute;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    max-height: 84px;
    .contents-title {
      font-size: 15px;
    }
    .contents-zy {
      font-size: 13px;
      overflow: hidden;
    }
  }
}
</style>
